// ==UserScript==
// @name         搜搜网站添加一个全部打开按钮
// @namespace    http://tampermonkey.net/
// @version      2024-11-07
// @description  try to take over the world!
// @author       You
// @match        https://cn.bing.com/search?*
// @match        www.baidu.com/*
// @icon         http://wuweijun.fun/favicon.ico
// @grant        none
// ==/UserScript==

(function () {
  'use strict';

  // 通过隐藏的方式去掉广告
  var data = [
    { hostname: 'cn.bing.com', fun: bing },
    { hostname: 'www.baidu.com', fun: baidu },
  ]
  for (let index = 0; index < data.length; index++) {
    const element = data[index];
    if (location.href.includes(element.hostname)) {
      try {
        let k = document.createElement('div');
        k.innerHTML = '点击全部'
        k.style = `width: 60px; height: 60px; position: fixed; top: 150px;
                right: 30px; background-color: rgb(177, 171, 171); border-radius: 50%;
                display: flex; align-items: center;
                justify-content: center; color: white; font-size: 11px;`
        document.body.appendChild(k);
        k.onclick = data[index]['fun']
      } catch (error) {
        console.log(error)
      }
    }
  }


  function bing() {
    console.clear();
    let exclude = /qidian|qq|qdmm|readnovel|xs8|rongshuxia|hongxiu|qidiantu/g
    document.querySelectorAll(".b_algo .b_tpcn > a").forEach((item) => {
      if (item.href && !item.href.match(exclude)) {
        // console.log(``, exclude.test(item.href), item.href)
        item.click();
      }
    })
    document.querySelector(".sb_pagN").click();
  }

  function baidu() {
    document.querySelectorAll("h3 a").forEach((item) => {
      item.click();
    })
    if (document.querySelector("#page > div > a:nth-child(12)")) document.querySelector("#page > div > a:nth-child(12)").click();
    else document.querySelector("#page > div > a.n").click();
  }

  // Your code here...
})();